#!python
import os

env = Environment()

platform = ARGUMENTS.get("p", "linux")
godot_headers_path = ARGUMENTS.get("headers", "godot_headers/")
godot_bindings_path = ARGUMENTS.get("cpp_bindings", "cpp_bindings/")
godot_src_path = ARGUMENTS.get("godotpath", "../../../../godot3-git/")

godot_name = "godot." + ("x11" if platform == "linux" else platform) + ".tools.64"

if ARGUMENTS.get("use_llvm", "no") == "yes":
    env["CXX"] = "clang++"

# put stuff that is the same for all first, saves duplication 
if platform == "osx":
    env.Append(CCFLAGS = ['-g','-O3', '-std=c++14', '-arch', 'x86_64'])
    env.Append(LINKFLAGS = ['-arch', 'x86_64', '-framework', 'Cocoa', '-Wl,-undefined,dynamic_lookup'])
elif platform == "linux":
    env.Append(CCFLAGS = ['-g','-O3', '-std=c++14', '-Wno-writable-strings'])
    env.Append(LINKFLAGS = ['-Wl,-R,\'$$ORIGIN\''])
elif platform == "windows":
    # need to add detection of msvc vs mingw, this is for msvc...
    env.Append(CCFLAGS = ['/MD', '/WX', '/O2', '/EHsc', '/nologo'])
    env.Append(LINKFLAGS = ['/WX'])

def add_sources(sources, dir):
    for f in os.listdir(dir):
        if f.endswith(".cpp"):
            sources.append(dir + "/" + f)

env.Append(CPPPATH=[godot_headers_path, godot_bindings_path + 'include/', godot_bindings_path + 'include/core/', 'src' ])

env.Append(LIBS=['godot_cpp_bindings'])
env.Append(LIBPATH=[ godot_bindings_path + 'bin/' ])

if platform == "windows":
    env.Append(LIBS=[ godot_name ]) 
    env.Append(LIBPATH=[ godot_src_path + 'bin/' ])

sources = []
add_sources(sources, "src")

library = env.SharedLibrary(target='bin/libkinematic_char', source=sources)
Default(library)

